Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix imm_or_funct7 #498

Merged
merged 1 commit into from
Oct 30, 2024
Merged

Fix imm_or_funct7 #498

merged 1 commit into from
Oct 30, 2024

Conversation

matthiasgoergens
Copy link
Collaborator

@matthiasgoergens matthiasgoergens commented Oct 30, 2024

Previously we relied on a hacky co-incidence.

@naure
Copy link
Collaborator

naure commented Oct 30, 2024

The field DecodedInstruction::rs2 is specifically the bits 20:25 of the instruction, interpreted differently depending on the instruction type. In fact this PR still uses it as part of imm_i.

If you want to change something, I suggest just renaming the fields (e.g. rs2 -> bits_20_25).

@naure
Copy link
Collaborator

naure commented Oct 30, 2024

I suppose the naming scheme was this. First the instruction is decoded into all fields besides immediate pieces. Most visible in the R-type. Then these fields are either interpreted as what they’re named after, or they are combined in one of the immediate format.

image

@matthiasgoergens
Copy link
Collaborator Author

The subset of RiscV instructions we picked happen to all have either no rs2 specified or have their rs2 in the same location.

Other RiscV instructions have their rs2 in different locations.

If we want to have some abstraction and meaning, then the field rs2 in the DecodedInstruction should stand for the index of the second input register of that instruction, no matter where that information is located in the bits. If the instruction in question doesn't use a second input register, rs2 should be None or 0 or so, not some random bits.

If we want the field rs2 to mean 'give me some arbitrary bits without regard to their meaning', then I agree with your suggestion for a rename.

But why stop there? If we just want to use the bits as bits, what's the point of having DecodedInstruction at all? Just use a naked u32 and be done with it.

@matthiasgoergens matthiasgoergens merged commit c8827eb into master Oct 30, 2024
6 checks passed
@matthiasgoergens matthiasgoergens deleted the matthias/fix-shift branch October 30, 2024 14:56
@naure
Copy link
Collaborator

naure commented Oct 30, 2024

Keep in mind you are looking at private details of a decoder here. It handles bit fields of some data format; it knows nothing about the VM. Variables have names as suggested by the diagram (I presume).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants